package com.hs.room.repository

import android.content.Context
import com.hs.room.AppDatabase
import com.hs.room.model.sys.SysLog
import com.hs.room.repository.service.ISysLogRepository
import dagger.hilt.android.qualifiers.ApplicationContext
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject

class SysLogRepository @Inject constructor(
    @ApplicationContext var context: Context,
    val database: AppDatabase
) : ISysLogRepository {

    override fun insertLog(sysLog: SysLog) {
        database.sysLogDao().insertSysLog(sysLog)
    }

    override suspend fun updateLog(sysLog: SysLog): Int {
        return database.sysLogDao().updateSysLog(sysLog)
    }

    /**
     * 查询数据
     */
    override suspend fun getSysLogs(): Flow<List<SysLog>> {
        return database.sysLogDao().getSysLogs()
    }

    /**
     * 按照条件查询
     */
    override suspend fun getByCombinedConditions(
        pageIndex: Int,
        pageSize: Int
    ): Flow<List<SysLog>> {
        return database.sysLogDao().getByCombinedConditions(pageIndex,pageSize)
    }

    override suspend fun getAllCountByCombinedConditions(): Int {

        return database.sysLogDao().getAllCountByCombinedConditions()
    }

    override fun count(): Int {
        return database.sysLogDao().count()
    }
}